/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.figures;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.text.FlowPage;
import org.eclipse.draw2d.text.ParagraphTextLayout;
import org.eclipse.draw2d.text.TextFlow;
import org.eclipse.swt.graphics.Color;


/**
 * A Figure with a bent corner and an embedded TextFlow within a FlowPage that contains
 * text.
 * 
 * @see org.eclipse.gef.examples.ediagram.figures.StockNoteFigure
 */
public class RoundedStickyNoteFigure extends RoundedRectangleNodeFigure {

	/**
	 * The inner TextFlow *.
	 */
	protected TextFlow textFlow;

	protected ContainerBorder flowPageborder;
	/**
	 * Creates a new StickyNoteFigure with a default MarginBorder size of DEFAULT_CORNER_SIZE
	 * - 3 and a FlowPage containing a TextFlow with the style WORD_WRAP_SOFT.
	 */
	public RoundedStickyNoteFigure() {
		this(BentCornerFigure.DEFAULT_CORNER_SIZE - 3);
	}

	/**
	 * Creates a new StickyNoteFigure with a MarginBorder that is the given size and a
	 * FlowPage containing a TextFlow with the style WORD_WRAP_SOFT.
	 * 
	 * @param borderSize the size of the MarginBorder
	 */
	public RoundedStickyNoteFigure(int borderSize) {
		ToolbarLayout layout = new ToolbarLayout();
		setLayoutManager(layout);
		layout.setSpacing(2);
		setBorder(new MarginBorder(borderSize));
		FlowPage flowPage = new FlowPage();
		this.textFlow = new TextFlow();
		this.textFlow.setLayoutManager(new ParagraphTextLayout(this.textFlow,
				ParagraphTextLayout.WORD_WRAP_TRUNCATE));
		flowPageborder= new ContainerBorder(ColorConstants.red, 0, 5, 5, 0, -5);
		flowPage.setBorder(flowPageborder);
		flowPage.add(this.textFlow);
		flowPage.setForegroundColor(ColorConstants.black);
		this.add(flowPage);
	}

	public void setBorderColor(Color borderColor) {
		this.borderColor = borderColor;
		this.textFlow.setForegroundColor(borderColor);
		super.setBorder(new LineBorder(borderColor));
	}
	
	public void setBackgroundColor(Color backgroundColor) {
		super.setBackgroundColor(backgroundColor);
		flowPageborder.setColor(backgroundColor);
		
	}
	
	/**
	 * Returns the text inside the TextFlow.
	 * 
	 * @return the text inside the text flow.
	 */
	public String getText() {
		return this.textFlow.getText();
	}

	/**
	 * Sets the text of the TextFlow to the given value.
	 * 
	 * @param newText the new text value.
	 */
	public void setText(String newText) {
		this.textFlow.setText(newText);
	}
	
	/**
	 * Returns the text flow where text is displayed.
	 * 
	 * @return the text flow where text is displayed
	 */
	public TextFlow getTextFigure() {
		return textFlow;
	}
	


	public Dimension getMinimumDimension() {
		return new Dimension(200,100);
	}
}